<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="批次名称" prop="bisAdlPcName">
            <el-input v-model="form.bisAdlPcName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="执行日期" prop="bisAdlPcZxrq">
            <el-date-picker v-model="form.bisAdlPcZxrq" type="date" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="标准文件">
            <el-input v-model="form.bisAdlPcBzwj" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.bisAdlPcZt" filterable placeholder="请选择" style="width: 370px;">
              <el-option
                v-for="item in dict.adlzt"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="bisAdlPcName" label="批次名称" />
        <el-table-column prop="bisAdlPcZxrq" label="执行日期" />
        <el-table-column prop="bisAdlPcBzwj" label="标准文件" />
        <el-table-column prop="bisAdlPcZt" label="状态" header-align="center" align="center" width="250px">
          <template slot-scope="scope">
            <el-radio-group v-model="scope.row.bisAdlPcZt">
              <el-radio-button label="adlzt01">未执行</el-radio-button>
              <el-radio-button label="adlzt02">已执行</el-radio-button>
              <el-radio-button label="adlzt03">已作废</el-radio-button>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-s-grid"
              @click="openAldXm(scope.row.bisAdlPcId)"
            >
              维护ADL项目
            </el-button>
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','adlPc:edit','adlPc:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <adlXm ref="adlXm" />
    </div>
  </div>
</template>

<script>
import adlXm from './adlXm'
import crudAdlPc from '@/api/business/adlPc'
import CRUD, { presenter, header, form } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisAdlPcId: null, bisAdlPcName: null, bisAdlPcZxrq: null, bisAdlPcZfrq: null, bisAdlPcBzwj: null, bisAdlPcZt: null, adlXms: [], ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, sfyx: null, bz: null }
export default {
  name: 'AdlPc',
  components: { pagination, crudOperation, rrOperation, udOperation, adlXm },
  mixins: [presenter(), header(), form(defaultForm)],
  dicts: ['adlzt'],
  cruds() {
    return CRUD({ title: 'ADL批次', url: 'api/adlPc', sort: 'bisAdlPcId,desc', crudMethod: { ...crudAdlPc }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'adlPc:add'],
        edit: ['admin', 'adlPc:edit'],
        del: ['admin', 'adlPc:del']
      },
      rules: {
        bisAdlPcName: [
          { required: true, message: '批次名称不能为空', trigger: 'blur' }
        ],
        bisAdlPcZxrq: [
          { required: true, message: '执行日期不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'bisAdlPcName', display_name: '批次名称' },
        { key: 'bisAdlPcBzwj', display_name: '标准文件' },
        { key: 'bisAdlPcZt', display_name: '状态' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    openAldXm(bisAdlPcId) {
      this.$refs.adlXm.dialog = true
      this.$refs.adlXm.bisAdlPcId = bisAdlPcId
      this.$refs.adlXm.query.bisAdlPcId = bisAdlPcId
      this.$refs.adlXm.crud.toQuery()
    },
    // 改变状态
    changeEnabled(data, val) {
      this.$confirm('此操作将 "' + this.dict.label.job_status[val] + '" ' + data.name + '岗位, 是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // eslint-disable-next-line no-undef
        crudJob.edit(data).then(() => {
          // eslint-disable-next-line no-undef
          this.crud.notify(this.dict.label.job_status[val] + '成功', 'success')
        }).catch(err => {
          data.enabled = !data.enabled
          console.log(err.data.message)
        })
      }).catch(() => {
        data.enabled = !data.enabled
      })
    }
  }
}
</script>

<style scoped>

</style>
